package com.qr.controller;

import com.qr.constant.Constant;
import com.qr.dto.SuggestDTO;
import com.qr.dto.UserSubmitDTO;
import com.qr.entity.UserExercise;
import com.qr.result.Result;
import com.qr.service.MoveService;
import com.qr.vo.NavVO;
import com.qr.vo.TimeVO;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Set;

@RestController
@Slf4j
public class MoveController {

    @Autowired
    private MoveService moveService;

    @GetMapping("/getNavItem")
    public Result<List<NavVO>> getNavItem() {
        // 获取NavItem以及对应move
        List<NavVO> list = moveService.getNavItem();

        return Result.success(list, Constant.SELECT_SUCCESS);
    }

    @PostMapping("/submit")
    public Result<String> submit(@RequestBody List<UserSubmitDTO> submitdto) {
        // 提交move
        log.info("提交的数据为：{}", submitdto);
        moveService.submit(submitdto);
        return Result.success( Constant.SUBMIT_SUCCESS);
    }

    @GetMapping("/getDataByDate")
    public Result<List<UserExercise>> getDataByDate(String date) {
        // 根据日期获取当天的所有动作
        log.info("获取的日期为：{}", date);
        List<UserExercise> listData = moveService.getDataByDate(date);
        return Result.success(listData, Constant.SELECT_SUCCESS);
    }

    @PostMapping("/updateData")
    public Result<String> updateData(@RequestBody UserExercise userExercise) {
        // 更新动作
        log.info("更新的数据为：{}", userExercise);
        moveService.updateData(userExercise);
        return Result.success("");
    }

    //获取选择时间内的每个动作的次数
    @GetMapping("/getTimesByDate")
    public Result<List<TimeVO>> getTimesByDate(LocalDate beginDate, LocalDate endDate) {
        log.info("获取的开始日期为：{}", beginDate);
        log.info("获取的结束日期为：{}", endDate);
        List<TimeVO> timesByDate = moveService.getTimesByDate(beginDate, endDate);
        return Result.success(timesByDate, Constant.SELECT_SUCCESS);
    }

    /**
     * 获取选择时间内的对应部位的每个动作的次数
     * @param id
     * @param beginDate
     * @param endDate
     * @return
     */
    @GetMapping("/getMoveTimesByDate")
    public Result<List<TimeVO>> getMoveTimesByDate(Integer id, LocalDate beginDate, LocalDate endDate) {
        log.info("获取的开始日期为：{}", beginDate);
        log.info("获取的结束日期为：{}", endDate);
        List<TimeVO> moveTimes = moveService.getMoveTimesByDate(id, beginDate, endDate);
        return Result.success(moveTimes, Constant.SELECT_SUCCESS);
    }


    @PostMapping("/submitSuggest")
    public Result<String> submitSuggest(@RequestBody SuggestDTO suggestdto) {
        // 提交建议
        log.info("提交的建议为：{}", suggestdto);
        moveService.submitSuggest(suggestdto);
        return Result.success(Constant.SUBMIT_SUCCESS);
    }

    //获取范围日期内的哪天有数据
    @GetMapping("/getDataByDateRange")
    public Result<List<String>> getDataByDateRange(LocalDate startDate, LocalDate endDate) {
        log.info("获取的开始日期为：{}", startDate);
        log.info("获取的结束日期为：{}", endDate);
        List<String> list = moveService.getDataByDateRange(startDate, endDate);
        return Result.success(list,Constant.SELECT_SUCCESS);
    }
}
